import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 2打开浏览器
# 设置Chrome测试版本的位置
# 配置到实例
driver = webdriver.Chrome()
# 3访问页面
driver.get("https://hmshop-test.itheima.net/Admin/Admin/login")
# 4页面操作(找元素+找元素操作)
# 4.1 输入用户名
driver.find_element(By.CSS_SELECTOR,
                    "#theForm > div > div.formContent > div.formInfo > div:nth-child(1) > input").send_keys("admin")
# 4.2输入用户密码
driver.find_element(By.CSS_SELECTOR,
                    "#theForm > div > div.formContent > div.formInfo > div:nth-child(2) > input").send_keys(
    "HM_2023_test")
# 4.3输入验证码
driver.find_element(By.CSS_SELECTOR, "#vertify").send_keys("8888")
# 4.4点击登录
time.sleep(3)
driver.find_element(By.CSS_SELECTOR,
                    "#theForm > div > div.formContent > div.formInfo > div.formText.submitDiv > span > input").click()
# 5关闭浏览器
time.sleep(3)
driver.quit()
